<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <title>认筹</title>
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/zhifu.css">
    <script src="js/jquery-1.10.1.min.js"></script>
    <!--<script src="passwordBox.min.js"></script>-->
    <script src="js/layer.js"></script>
    <link rel="stylesheet" href="css/layer.css">
</head>
<body>
<div class="title">
    <i class="iconfont">&#xe613;</i>
    <p>认筹</p>
</div>
<div class="recognize">
<div class="money">
    <div class="money-number">

       <span id="price"></span>
    </div>

</div>
    <div style="clear: both"></div>
<div class="number">
<div class="number-1">
<p>总计发行量</p>
<p id="total"></p>
</div>
<div class="number-1">
    <p>剩余认购总量</p>
    <p id="residue"></p>
</div>
</div>
<div class="btn-number">
    <input type="text" placeholder="请输入认购数量" id="test">
    <input type="text" placeholder="" style="display: none">
<button>认筹</button>
</div>
</div>

<div class="ftc_wzsf">
    <div class="numb_box">
        <div class="srzfmm_box">
            <div class="qsrzfmm_bt clear_wl">
                <img src="images/xx_03.jpg" class="tx close fl">
                <!--<img src="images/jftc_03.png" class="tx fl">-->
                <p class="fl">请输入支付密码</p></div>
            <ul class="mm_box">
                <li></li><li></li><li></li><li></li><li></li><li></li>
            </ul>
        </div>
        <div class="xiaq_tb">安全支付环境，请放心使用！</div>
        <ul class="nub_ggg">
            <li><a href="javascript:void(0);" class="zf_num">1</a></li>
            <li><a href="javascript:void(0);" class="zj_x zf_num">2</a></li>
            <li><a href="javascript:void(0);" class="zf_num">3</a></li>
            <li><a href="javascript:void(0);" class="zf_num">4</a></li>
            <li><a href="javascript:void(0);" class="zj_x zf_num">5</a></li>
            <li><a href="javascript:void(0);" class="zf_num">6</a></li>
            <li><a href="javascript:void(0);" class="zf_num">7</a></li>
            <li><a href="javascript:void(0);" class="zj_x zf_num">8</a></li>
            <li><a href="javascript:void(0);" class="zf_num">9</a></li>
            <li><a href="javascript:void(0);" class="zf_empty">清空</a></li>
            <li><a href="javascript:void(0);" class="zj_x zf_num">0</a></li>
            <li><a href="javascript:void(0);" class="zf_del">删除</a></li>
        </ul>
    </div>
</div>

<div class="hbbj"></div>
<div class="msg"></div>

<div id="tan">
    <p>需要支付￥<span></span></p>
    <button class="btn-color">确定</button> <button class="btn-close">取消</button>
</div>


</body>




<script>
    $(function(){
        $(".iconfont").click(function () {
                window.location.href="index.html";
        });

    });
   $("#tan").hide();

    $(".btn-close").click(function () {
        $("#tan").hide()
    });
    //	监听键盘 前往 事件
    $("#test").keydown(function (e) {
        console.log('键盘输入');
        if (e.keyCode === 13)
        {
            $(".btn-number button").trigger('click');
            $("#test").blur();
        }
    });

    $(function(){
        $.ajax({
            url:`${localStorage.top}api/index/get_chip?TOKEN=${localStorage.token}`,    //请求的url地址
            dataType:"json",   //返回格式为json
            async:true,//请求是否异步，默认为异步，这也是ajax重要特性
            type:"GET",   //请求方式
            success:function(data){
                //请求成功时处理
                var uid=data.data.id;
                localStorage.price=data.data.price;
                console.log("单价"+localStorage.price);
                $("#price").html("￥"+data.data.price);
                $("#residue").html(data. data.residue);
                $("#total").html(data.data.total);

                    $(".btn-number button").unbind('click').click(function () {
                        $.ajax({
                            url:`${localStorage.top}api/UserCenter/check_pay_password?TOKEN=${localStorage.token}`,    //请求的url地址
                            dataType:"json",   //返回格式为json
                            async:true,//请求是否异步，默认为异步，这也是ajax重要特性
                            type:"POST",

                            success:function(data){
                                console.log(data.code);
                                //请求成功时处理
                                if(data.code===1){
                                    if($("#test").val()===''){
                                        layer.msg("认购数量不能为空");
                                    }else {

                                        localStorage.test=$(" #test ").val();
                                        $("#tan span").html(Math.floor(localStorage.price* localStorage.test* 10000) / 10000);
                                        $("#tan").show();

                                        $(".btn-color").unbind('click').click(function () {
                                            $("#tan").hide();
                                            $(".ftc_wzsf").show();
                                            $(".hbbj").show();
                                            console.log("认筹数量"+localStorage.test);

                                            var i = 0;
                                            $(".nub_ggg li .zf_num").unbind('click').click(function(){
                                                if(i<6){
                                                    $(".mm_box li").eq(i).addClass("mmdd");
                                                    $(".mm_box li").eq(i).attr("data",$(this).text());
                                                    i++
                                                    if (i==6) {
                                                        setTimeout(function(){
                                                            var password = "";
                                                            $(".mm_box li").each(function(){
                                                                password += $(this).attr("data");
                                                            });
                                                            console.log("支付密码"+password);
                                                            console.log("认筹ID"+uid);
                                                            $.ajax({
                                                                url:`${localStorage.top}api/index/recognition_chip?TOKEN=${localStorage.token}`,    //请求的url地址
                                                                data :{'chip_id':uid,'chip_num':localStorage.test,'pay_password':password,},
                                                                dataType:"json",   //返回格式为json
                                                                async:true,//请求是否异步，默认为异步，这也是ajax重要特性
                                                                type:"GET",
                                                                success:function(data){
                                                                    //请求成功时处理
                                                                    console.log(data);
                                                                    // alert(data.msg);
                                                                    $(".ftc_wzsf").hide();
                                                                    $(".hbbj").hide();
                                                                    $(".mm_box li").removeClass("mmdd");
                                                                    $(".mm_box li").attr("data","");
                                                                    i = 0;
                                                                    $(" #test ").val("");
                                                                    layer.msg(data.msg);
                                                                    if(data.code===1){
                                                                        setTimeout(function () {
                                                                            window.location.href='index.html'
                                                                        },2000);
                                                                    }
                                                                },
                                                                error:function(data){

                                                                }
                                                            });

                                                        },100);
                                                    };
                                                }
                                            });
                                            $(".nub_ggg li .zf_del").unbind('click').click(function(){
                                                if(i>0){
                                                    i--
                                                    $(".mm_box li").eq(i).removeClass("mmdd");
                                                    $(".mm_box li").eq(i).attr("data","");
                                                }
                                            });
                                            $(".nub_ggg li .zf_empty").unbind('click').click(function(){
                                                $(".mm_box li").removeClass("mmdd");
                                                $(".mm_box li").attr("data","");
                                                i = 0;
                                            });
                                            $(".ftc_wzsf .close").unbind('click').click(function(){
                                                $(".ftc_wzsf").hide();
                                                $(".hbbj").hide();
                                                $(".mm_box li").removeClass("mmdd");
                                                $(".mm_box li").attr("data","");
                                                i = 0;
                                            });

                                        })

                                    }
                                }else {
                                    layer.msg("请设置交易密码");
                                    setTimeout('window.location.href = "../personal/xiugaijiaoyimima.html"',1000);
                                }

                            },
                            error:function(data){

                            }
                       });
                 });
            },
        });
    })
</script>
</html>